const defaultState = {
    inputValue: '',
    inputValue1: '',
    inputValue2: '',
    inputValue3: '',
    list: [],
    data:[],
    post:[],
    delete:[],
    put:[]
}
export default reducer = (state = defaultState, action) => {
    if (action.type === 'changeInput') {
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputValue = action.value
        // console.log(newState)
        return newState
    }
    if (action.type === 'changeInput1') {
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputValue1 = action.value
        // console.log(newState)
        return newState
    }
    if (action.type === 'changeInput2') {
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputValue2 = action.value
        // console.log(newState)
        return newState
    }
    if (action.type === 'changeInput3') {
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputValue3 = action.value
        // console.log(newState)
        return newState
    }
    if (action.type === 'addItem') {
        let newState = JSON.parse(JSON.stringify(state))
        console.log(action.time)
        let data={title:newState.inputValue,content:newState.inputValue1,time:action.time}
        newState.list.push(data)
        newState.inputValue=''
        newState.inputValue1=''
        return newState
    }
    if(action.type==='getItem'){
        let newState=JSON.parse(JSON.stringify(state))
        newState.data=action.data.data
        return newState
    }
    if(action.type==='postItem'){
        let newState=JSON.parse(JSON.stringify(state))
        newState.post=action.data
        return newState
    }
    if(action.type==='deleteItem'){
        let newState=JSON.parse(JSON.stringify(state))
        newState.delete=action.data
        return newState
    }
    if(action.type==='putItem'){
        let newState=JSON.parse(JSON.stringify(state))
        newState.put=action.data
        return newState
    }
    

    return state;
}